package com.zhijian.medical.controller;

import com.zhijian.medical.dao.local.RoutineSingleSampleQpMapper;
import com.zhijian.medical.entity.po.*;
import com.zhijian.medical.entity.vo.request.RoutineSampleArchiveSearchVo;
import com.zhijian.medical.entity.vo.request.RoutineSampleBrRecordSearchVo;
import com.zhijian.medical.entity.vo.request.RoutineSingleSampleQpSearchVo;
import com.zhijian.medical.entity.vo.request.RoutineSingleSampleSearchVo;
import com.zhijian.medical.entity.vo.response.RoutinePatientDiagnoseVo;
import com.zhijian.medical.entity.vo.response.RoutineSampleArchiveVo;
import com.zhijian.medical.entity.vo.response.RoutineSingleSampleVo;
import com.zhijian.medical.service.RoutineSampleArchiveService;
import com.zhijian.medical.service.RoutineSampleBrRecordService;
import com.zhijian.medical.service.RoutineSingleSampleQpService;
import com.zhijian.response.annotation.Response;
import com.zhijian.util.page.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Controller
@Api(tags = "常规病理-借还片记录")
public class RoutineSampleBrRecordController {

    @Autowired
    RoutineSampleBrRecordService routineSampleBrRecordService;

    @Autowired
    RoutineSingleSampleQpService routineSingleSampleQpService;

    @Autowired
    RoutineSingleSampleQpMapper routineSingleSampleQpMapper;

    /**
     * 待归档切片列表查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/routine/single/sample/qp/gd/list")
    @ApiOperation("常规病理-切片全部列表")
    public List<RoutineSingleSampleQp> sampleQpList(@RequestBody RoutineSingleSampleQpSearchVo param) {
        log.info("{} - {}| insert info", this.getClass().getSimpleName(), param);
        return routineSingleSampleQpService.selectList(param);
    }

    @Response
    @PostMapping("/routine/sample/record/info/{conventionPathologyNumber}")
    @ApiOperation("常规病理-病理详情数据")
    public RoutinePatientDiagnoseVo readDiagnose(@PathVariable("conventionPathologyNumber") String conventionPathologyNumber,
                                                 @RequestBody RoutinePatientDiagnose searchVo){
        searchVo.setConventionPathologyNumber(conventionPathologyNumber);
        return routineSampleBrRecordService.readDiagnoseVo(searchVo);
    }

    @Response
    @PostMapping("/routine/single/sample/lk/gd/list")
    @ApiOperation("常规病理-蜡块全部列表")
    public List<RoutineSingleSampleVo> sampleLkList(@RequestBody RoutineSingleSampleSearchVo param) {
        log.info("{} - {}| insert info", this.getClass().getSimpleName(), param);
        List<RoutineSingleSampleVo> sampleList = routineSingleSampleQpMapper.selectLkPageList(param);
        for (RoutineSingleSampleVo routineSingleSample : sampleList){
            String[] numberArr = routineSingleSample.getNumber().split("-");
            routineSingleSample.setBlh(numberArr[0]);
        }
        return sampleList;
    }

    @Response
    @PostMapping("/routine/sample/record/page")
    @ApiOperation("常规病理-切片借分页查询")
    public Page<RoutineSampleBrRecord> recordList(@RequestBody RoutineSampleBrRecordSearchVo param) {
        log.info("{} - {}| insert info", this.getClass().getSimpleName(), param);
        return routineSampleBrRecordService.selectPageList(param);
    }

    @Response
    @GetMapping("/routine/sample/record/info/{id}")
    @ApiOperation("常规病理-切片借详情查询")
    public RoutineSampleBrRecord recordInfo(@PathVariable("id") Long id) {
        log.info("{} - {}| insert info", this.getClass().getSimpleName(), id);
        return routineSampleBrRecordService.readOne(id);
    }

    @Response
    @PostMapping("/routine/sample/record/lk")
    @ApiOperation("常规病理-蜡块借片")
    public RoutineSampleBrRecord recordLkList(@RequestBody RoutineSampleBrRecord record) {
        log.info("{} - {}| insert info", this.getClass().getSimpleName(), record);
        record.setJyType(RoutineSampleArchiveService.ArchiveType.LK.getCode());
        return routineSampleBrRecordService.addRsb(record);
    }

    @Response
    @PutMapping("/routine/sample/record/lk/{id}")
    @ApiOperation("常规病理-蜡块修改")
    public RoutineSampleBrRecord updateLkList(@PathVariable("id") Long id, @RequestBody RoutineSampleBrRecord record) {
        record.setId(id);
        log.info("{} - {}| insert info", this.getClass().getSimpleName(), record);
        record.setJyType(RoutineSampleArchiveService.ArchiveType.LK.getCode());
        return routineSampleBrRecordService.updateRsb(record);
    }

    @Response
    @PutMapping("/routine/sample/record/return/lk/{id}")
    @ApiOperation("常规病理-蜡块还片")
    public RoutineSampleBrRecord recordLkList(@PathVariable("id") Long id, @RequestBody RoutineSampleBrRecord record) {
        record.setId(id);
        log.info("{} - {}| insert info", this.getClass().getSimpleName(), record);
        record.setJyType(RoutineSampleArchiveService.ArchiveType.LK.getCode());
        return routineSampleBrRecordService.ghRsb(record);
    }

    @Response
    @PostMapping("/routine/sample/record/qp")
    @ApiOperation("常规病理-切片借片")
    public RoutineSampleBrRecord recordQpList(@RequestBody RoutineSampleBrRecord record) {
        log.info("{} - {}| insert info", this.getClass().getSimpleName(), record);
        record.setJyType(RoutineSampleArchiveService.ArchiveType.QP.getCode());
        return routineSampleBrRecordService.addRsb(record);
    }

    @Response
    @PutMapping("/routine/sample/record/qp/{id}")
    @ApiOperation("常规病理-切片修改")
    public RoutineSampleBrRecord updateQpList(@PathVariable("id") Long id, @RequestBody RoutineSampleBrRecord record) {
        record.setId(id);
        log.info("{} - {}| insert info", this.getClass().getSimpleName(), record);
        record.setJyType(RoutineSampleArchiveService.ArchiveType.QP.getCode());
        return routineSampleBrRecordService.updateRsb(record);
    }

    @Response
    @PutMapping("/routine/sample/record/return/qp/{id}")
    @ApiOperation("常规病理-切片还片")
    public RoutineSampleBrRecord recordQpList(@PathVariable("id") Long id, @RequestBody RoutineSampleBrRecord record) {
        record.setId(id);
        log.info("{} - {}| insert info", this.getClass().getSimpleName(), record);
        record.setJyType(RoutineSampleArchiveService.ArchiveType.QP.getCode());
        return routineSampleBrRecordService.ghRsb(record);
    }
}
